package com.hongsen.cn.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.hongsen.cn.Utils.LogUtil;
import com.hongsen.cn.Utils.RxBus;
import com.hongsen.cn.Utils.SPUtil;
import com.hongsen.cn.adapter.WorkDescAdapter;
import com.hongsen.cn.base.BaseActivity;
import com.hongsen.cn.bean.BaseTitleBean;
import com.hongsen.cn.bean.OrderBean;
import com.hongsen.cn.bean.RxValue;
import com.hongsen.cn.bean.TitleBean;
import com.hongsen.cn.contract.WorkDescView;
import com.hongsen.cn.dayandmonth.R;
import com.hongsen.cn.dayandmonth.databinding.ActivityWorkDescBinding;
import com.hongsen.cn.presenter.WorkDescPersenter;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;

import static com.hongsen.cn.bean.Constants.WORK_DESC_PATH;
import static com.hongsen.cn.bean.RxBusEventKey.BASE_TITLE_CLICK;

@Route(path = WORK_DESC_PATH)
public class WorkDescActivity extends BaseActivity<WorkDescPersenter> implements WorkDescView {

    public ActivityWorkDescBinding binding;
    public WorkDescAdapter adapter;
    public List<OrderBean> list = new ArrayList<>();
    public String type;


    @Override
    protected WorkDescPersenter createPresenter() {
        return new WorkDescPersenter(this);
    }

    @Override
    protected void initData() {


    }

    @SuppressLint("CheckResult")
    @Override
    protected void initView() {


        list = (List<OrderBean>) getIntent().getSerializableExtra("module_listBean");
        type = getIntent().getStringExtra("module_type");

        binding = DataBindingUtil.inflate(LayoutInflater.from(WorkDescActivity.this), R.layout.activity_work_desc, null, false);
        binding.setActivity(this);


        binding.tvModuleTitle.setText(type + "(" + list.size() + ")");
        binding.btnBack.setOnClickListener(this);

        TitleBean titleBean = TitleBean.getBean(WorkDescActivity.this);

        if (titleBean != null) {
            LogUtil.e("工作详情发送title数据");

            RxBus.getDefault().post(new RxValue("module_FBI_WG", titleBean.getTitleOne()));
            RxBus.getDefault().post(new RxValue("module_FBI_JD", titleBean.getTitleTwo()));
            RxBus.getDefault().post(new RxValue("module_FBI_JD_CC", titleBean.getTitleThree()));
            RxBus.getDefault().post(new RxValue("module_FBI_DT", titleBean.getTitleFour()));
            RxBus.getDefault().post(new RxValue("module_FBI_CS", titleBean.getTitleFive()));
        }else{
            LogUtil.e("工作详情titleBean== null");
        }


        /**
         * type类型变化
         */
        switch (type) {
            case "预约":
                binding.tvEvaluation.setText("时间");
                break;
            case "审批":
                binding.tvEvaluation.setText("审批类型");
                break;
            case "违规":
                binding.tvEvaluation.setText("违规类型");
                break;
            case "谈话":
                binding.tvEvaluation.setText("谈话类型");
                break;
            case "定位警情":
                binding.tvModuleLine.setVisibility(View.GONE);
                binding.tvEvaluation.setVisibility(View.GONE);
                break;
            default:
        }


        baseFl.addView(binding.getRoot());
        adapter = new WorkDescAdapter(this, list, type);
        binding.rlModule.setLayoutManager(new LinearLayoutManager(this));
        binding.rlModule.setAdapter(adapter);

    }

    @Override
    public void onClick(View v) {
        int sS_ID = v.getId();
        if (sS_ID == R.id.btnBack) {
            finish();
        }
    }

    @Override
    public void getTitleInfo(BaseTitleBean str) {
        RxBus.getDefault().post(new RxValue("module_FBI_WG", String.valueOf(str.getEffectiveVO().getNissinMonthlyCount())));
        RxBus.getDefault().post(new RxValue("module_FBI_JD", String.valueOf(str.getMechanicalDeviceVo().getNissinMonthlyCount())));
        RxBus.getDefault().post(new RxValue("module_FBI_JD_CC", String.valueOf(str.getMechanicalDeviceVo().getArePersonnelCount())));
        RxBus.getDefault().post(new RxValue("module_FBI_DT", String.valueOf(str.getRiskVO().getNissinMonthlyCount())));
        RxBus.getDefault().post(new RxValue("module_FBI_CS", String.valueOf(str.getOutVO().getNissinMonthlyCount())));
    }
}
